******************************
*Table 9: School-level  heterogeneity, by the child and the school-level attendance
 ************************
clear all
set trace off
set more off
clear
use school_heterogeneity_attendance.dta
rename total_attendance_2_help school_level_att
su school_level_att, detail
merge 1:m school_id using Jehanabad_analytic_sample_hemoglobin.dta

sort child_unique wave
gen att=total_attendance_2
replace att=total_attendance_2[_n+1] if wave==0
replace att=total_attendance_2 if att==.
replace att=total_attendance_2 if att==0
replace att=att[_n-1] if wave==1
g child_high_att_mean=(att> 0.73)

global socio_cov_1_vari no_HHmembers years_schooling_father years_schooling_mother asset_index
global school_cov_4_vari total_enrollment class_size student_teacher_ratio

g post=wave
label var post "Post"  /* Post denotes endline survey */
g treat_post=treat*post
label var treat_post "Treat*post"

g school_high=(school_level_att> 0.7483307 )  /* greater then school median att/ mean and median are same*/


** Table 9
eststo clear
foreach var in hemoglobin any_an mild_an mod_sev_an{
xtset child_unique wave
eststo: xtreg `var' treat##post##child_high_att_mean $socio_cov_1_vari $school_cov_4_vari if school_high==1, fe cluster (school_id)
eststo: xtreg `var' treat##post##child_high_att_mean $socio_cov_1_vari $school_cov_4_vari if school_high==0, fe cluster (school_id)


}

esttab using Table9.rtf, se(a3) keep(1.treat#1.post#1.child_high_att_mean 1.treat#1.post 1.post#1.child_high_att_mean ) ///
varwidth(35) b(a3) star(* 0.10 ** 0.05 *** 0.01) replace ///
title(*Table 9: School-level  heterogeneity, by the child and the school-level attendance)  mtitles("Hemoglobin (Hb g/dL) High" "Hemoglobin (Hb g/dL) Low" "Any anemia (High)" "Any anemia (Low)" "Mild anemia (High)" "Mild anemia (Low)"  "Moderate or severe anemia (High)" "Moderate or severe anemia (Low)") /// 
coeflabels(1.treat#1.post "Treat*post" 1.post#1.child_high_att_mean "Post x High child attendance" 1.treat#1.post#1.child_high_att_mean "Treat x Post x High child attendance") nonotes label ///
addnotes("Notes: Each column were estimated separately. Standard errors, clustered at the school level, are reported" ///
"in parentheses. All regressions include child fixed effects and time-variant household & school-level controls reported" ///
"in Table 4. Any anemia is defined as a hemoglobin value < 11.5 g/dl, mild anemia is defined as a hemoglobin value ≥ 11 & < 11.5 g/dl," ///
"moderate/severe anemia is defined as a hemoglobin value < 11 g/dl. High (low) groups are defined as attendance greater (smaller) than" ///
"mean attendance in the group.")  



********************************************End of do file *******************


